<template>
  <div>
    <el-table :data="serviceList" border style="width: 100%">
      <el-table-column type="index" label="ID" width="50"></el-table-column>
      <el-table-column prop="productTitle" label="服务名称"></el-table-column>
      <el-table-column prop="hospitalName" label="医院" width="100"></el-table-column>
      <el-table-column prop="status" label="状态" width="100">
        <template slot-scope="scope">{{showStatus(scope.row.status)}}</template>
      </el-table-column>
      <el-table-column prop="created_at" label="购买时间" width="160"></el-table-column>
      <el-table-column label="操作" width="80">
        <template slot-scope="scope">
          <el-button @click="info(scope.row.id)" size="mini">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="margin-top-20 text-center" v-if="serviceList.length">
      <el-pagination
        @size-change="pageSizeChange"
        @current-change="currentPageChange"
        :background="true"
        :current-page="currentPage"
        :page-sizes="[10, 20, 30]"
        :page-size="size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </div>
    <el-dialog title="服务详情" :visible.sync="dialogServiceVisible" width="70%" append-to-body>
      <Info
        :service="service"
        :dowloadServiceImages="this.formatDownloadServiceImage(this.service)"
      />
    </el-dialog>
  </div>
</template>

<script>
import Info from "@/components/pet/treatment/Info.vue";

export default {
  data() {
    return {
      service: {},
      dialogServiceVisible: false
    };
  },
  props: ["serviceList", "total", "currentPage", "size"],
  components: {
    Info
  },
  methods: {
    getServiceInfoData(id) {
      this.axios.get("/doctor/services/" + id).then(response => {
        if (response.data.code == 200) {
          this.service = response.data.data;
        } else {
          this.$message({
            message: response.data.msg,
            type: "error"
          });
        }
      });
    },
    formatDownloadServiceImage(serviceInfo) {
      if (typeof serviceInfo.service_file_upload !== "undefined")
        return JSON.parse(JSON.parse(serviceInfo.service_file_upload));
    },
    pageSizeChange(val) {
      this.page.currentPage = 1;
      this.page.size = val;
      this.getServiceInfoData();
    },
    currentPageChange(val) {
      this.page.currentPage = val;
      this.getServiceInfoData();
    },
    showStatus(status) {
      switch (status) {
        case 0:
          return "未验证";
          break;
        case 1:
          return "已验证";
          break;
        case 2:
          return "已上传";
          break;
        case 3:
          return "已确认";
          break;
        default:
          return "无效";
          break;
      }
    },
    info(service_id) {
      this.getServiceInfoData(service_id);
      this.dialogServiceVisible = true;
    }
  }
};
</script>
